package cn.gemframe.exception;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import cn.gemframe.response.ResultData;

/**
 * @Title:异常帮助类
 * @Description:异常帮助类
 * @author zhangysh
 * @date 2019年3月29日 15:45:36
 * @version V1.0
 */
@Slf4j
@ControllerAdvice
public class GemExceptionHandler {
	
	@ExceptionHandler(value = Exception.class)
	public ResultData defaultErrorHandler(HttpServletRequest request,HttpServletResponse response,Exception exception)  {
		//exception.printStackTrace();
        log.error("--- 拦截到了非检验型异常,异常信息如下: {}",exception);
        if(exception instanceof GemException){
			GemException httpException=(GemException)exception;
			//return ResponseEntity.status(httpException.getHttpStatus()).body(ResultData.getServerErrorResult(httpException.getCode(),httpException.getMsg()));
			return ResultData.builder().code(httpException.getCode()).msg(httpException.getMsg()).build();
		}
		return ResultData.getServerErrorResult();

	}
}
